<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>IFE ECMAScript</title>
</head>

<body>
    <input id="first-number" type="number" value="0" placeholder="第一个数字">
    <input id="second-number" type="number" value="0" placeholder="第二个数字">
    <button id="add-btn">加</button>
    <button id="minus-btn">减</button>
    <button id="times-btn">乘</button>
    <button id="divide-btn">除</button>
    <p id="result">运算结果</p>
    <script>
        var add = document.getElementById('add-btn');
        var minus = document.getElementById('minus-btn');
        var times = document.getElementById('times-btn');
        var divide = document.getElementById('divide-btn');
        add.onclick = function() {
            var num1 = document.getElementById('first-number').value;
            var num2 = document.getElementById('second-number').value;
            if (isNaN(parseInt(num1) + parseInt(num2))) {
                console.log('数字输入有误');
            } else {
                document.getElementById('result').innerHTML = '运算结果：' + (parseInt(num1) + parseInt(num2));
            }
        }
        minus.onclick = function() {
            var num1 = document.getElementById('first-number').value;
            var num2 = document.getElementById('second-number').value;
            if (isNaN(parseInt(num1) + parseInt(num2))) {
                console.log('数字输入有误');
            } else {
                document.getElementById('result').innerHTML = '运算结果：' + (parseInt(num1) - parseInt(num2));
            }
        }
        times.onclick = function() {
            var num1 = document.getElementById('first-number').value;
            var num2 = document.getElementById('second-number').value;
            if (isNaN(parseInt(num1) + parseInt(num2))) {
                console.log('数字输入有误');
            } else {
                document.getElementById('result').innerHTML = '运算结果：' + (parseInt(num1) * parseInt(num2));
            }
        }
        divide.onclick = function() {
            var num1 = document.getElementById('first-number').value;
            var num2 = document.getElementById('second-number').value;
            if (num2 == 0) {
                console.log('输入错误！除数不为0！')
            } else {
                if (isNaN(parseInt(num1) + parseInt(num2))) {
                    console.log('数字输入有误');
                } else {
                    document.getElementById('result').innerHTML = '运算结果：' + (parseInt(num1) / parseInt(num2));
                }
            }
        }
    </script>
</body>

</html>